package cn.bulibuqi.myblog.service;

import cn.bulibuqi.myblog.bean.Type;
import cn.bulibuqi.myblog.dao.TypeMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.awt.print.Pageable;
import java.util.List;

/**
 * @author bulibuqi
 * @create 2021-12-21:56
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper,Type> implements  TypeService{

    @Override
    public boolean saveType(Type type) {

        boolean save = save(type);
        return save;
    }

    @Override
    public Type getType(Long id) {

        Type byId = getById(id);
        return byId;
    }

    @Override
    public Page<Type> listType(Page pageInfo) {

        Page<Type> page = page(pageInfo);

        return page;
    }


    @Override
    public boolean updateType(Long id, Type type) {
        type.setId(id);
        boolean b = updateById(type);


        return b;
    }

    @Override
    public void deleteType(Long id) {
        removeById(id);

    }

    @Override
    public Type getTypeByName(String name) {
        QueryWrapper<Type> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        Type one = getOne(queryWrapper);
        return one;
    }
}
